# $Id$
# Maintainer:
# Contributor: Sarah Hay <sarahhay@mb.sympatico.ca>
# Contributor: roberto <roberto@archlinux.org>

pkgname=transcode
_sripver=0.3-4
pkgver=1.1.7
pkgrel=23
pkgdesc="A video/DVD ripper and encoder for the terminal/console"
arch=('i686' 'x86_64')
url="http://www.transcoding.org/"
license=('GPL')
depends=('gawk' 'imagemagick' 'lzo' 'libdvdread' 'ffmpeg' 'mjpegtools'
	 'libmpeg2' 'libxaw' 'libxv' 'a52dec' 'libxml2')
makedepends=('nasm' 'libx264')
source=(https://bitbucket.org/france/transcode-tcforge/downloads/${pkgname}-${pkgver}.tar.bz2
	http://downloads.sourceforge.net/sourceforge/subtitleripper/subtitleripper-${_sripver}.tgz
        subtitleripper-0.3.4-linkingorder.patch
	subtitleripper-0.3.4-respect-ldflags.patch
	transcode-1.1.7-ffmpeg.patch
	transcode-1.1.7-ffmpeg-0.10.patch
        transcode-1.1.7-ffmpeg-0.11.patch 
	transcode-1.1.7-preset-free.patch
	transcode-1.1.7-libav-9.patch 
	transcode-1.1.7-preset-force.patch
	transcode-1.1.7-ffmpeg2.patch
        transcode-1.1.7-ffmpeg-2.4.patch
	transcode-1.1.7-ffmpeg29.patch # rpmfusion
	transcode-ffmpeg3.patch)
sha1sums=('e35df68b960eb56ef0a59a4cdbed1491be56aee6'
          'd93ff3578dd5f722c8f4ef16bc0903eec5781a0d'
          'fa05aa1770d9350d90b7cf315aa7c4a1fd921ac7'
          '591943a33235342a66c3df0625a164a1479c09ae'
          'cc81c190db51d8a64623e2eea3b327ec7eb7ec57'
          '3b1590f30f8f32350444f668584ec31be6e8e614'
          '3f7b0257f023df6ea249111d247a852c46261c2f'
          '54b1bab48a0b3bc0e8464c4deb4de31bf1060a1c'
          'ef1cccd35317d3a28443b654da49de731cdf1766'
          '034853427bc784a80b333d2e2f4bab44f0b86ce0'
          '764de67996e2c4947346c7a91586cc4ca826a8e2'
          'b590dfc30cdc4bc2a6825de247928b46a8928a9a'
          'f034f9871a0e96d5aa682b69451961f3dd9c7309'
          '6aefa6a13fa70f8cc92ed03dd5383a4adcd4a6d0')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p0 -i "${srcdir}/transcode-1.1.7-ffmpeg.patch"
  patch -p0 -i "${srcdir}/transcode-1.1.7-ffmpeg-0.10.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-ffmpeg-0.11.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-preset-free.patch"
  patch -p0 -i "${srcdir}/transcode-1.1.7-libav-9.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-preset-force.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-ffmpeg2.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-ffmpeg-2.4.patch"
  patch -p1 -i "${srcdir}/transcode-1.1.7-ffmpeg29.patch"
  patch -p1 -i "${srcdir}/transcode-ffmpeg3.patch"
  sed -i 's|freetype/ftglyph.h|freetype2/freetype/ftglyph.h|' filter/subtitler/load_font.c

  cd ../subtitleripper
  patch -p1 -i "${srcdir}/subtitleripper-0.3.4-linkingorder.patch"
  patch -p1 -i "${srcdir}/subtitleripper-0.3.4-respect-ldflags.patch"
  sed -e 's|^\(.*lppm.*\)$|#\1|' \
      -e 's|^\(.*D_HAVE_LIB_PPM.*\)$|#\1|' \
      -e 's/DEFINES :=/DEFINES = -DHAVE_GETLINE/' \
      -i Makefile
}


build() {
  cd ${pkgname}-${pkgver}
  ./configure --prefix=/usr \
    --disable-sse --disable-sse2 --disable-altivec --enable-mmx \
    --enable-lame --enable-ogg --enable-vorbis --enable-theora \
    --enable-libdv --enable-libxml2 --enable-v4l \
    --enable-imagemagick --enable-libjpeg --enable-lzo --enable-mjpegtools \
    --enable-sdl --enable-freetype2 --enable-a52 --enable-libpostproc \
    --enable-xvid --enable-x264 --enable-alsa --enable-libmpeg2 --enable-libmpeg2convert
  make

  cd ../subtitleripper
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  cd ../subtitleripper
  install -m 755 pgm2txt "${pkgdir}/usr/bin/"
  install -m 755 srttool "${pkgdir}/usr/bin/"
  install -m 755 subtitle2pgm "${pkgdir}/usr/bin/"
  install -m 755 subtitle2vobsub "${pkgdir}/usr/bin/"
  install -m 755 vobsub2pgm "${pkgdir}/usr/bin/"
}
